package com.djl.rs.controller;
import com.djl.rs.mapper.StaffMapper;
import com.djl.rs.mapper.StaffSalaryMapper;
import com.djl.rs.model.Staff;
import com.djl.rs.model.StaffSalary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
//控制页面跳转的控制器
@Controller
public class pageChangeController {
    @Autowired
    private StaffMapper staffMapper;
    @Autowired
    private StaffSalaryMapper staffSalaryMapper;


    @RequestMapping("index")
    public String staff() {
        return "index";
    }


    @GetMapping("addStaffPage")
    public String addStaff() {
        return "addStaff";
    }

    @RequestMapping("allStaffs")
    public String allStaffs() {
        return "allStaffs";
    }

    @RequestMapping("updateStaff")
    public Object updateStaff(@RequestParam("sid") Integer sid, Model model) {
        Staff staff=staffMapper.findBySid(sid);
//        System.out.println(staff);
        model.addAttribute("sid", sid);
        model.addAttribute("name", staff.getName());
        model.addAttribute("borth", staff.getBorth());
        model.addAttribute("gender", staff.getGender());
        model.addAttribute("department", staff.getDepartment());
        model.addAttribute("education", staff.getEducation());
        return "updateStaff";
    }

    @RequestMapping("personalSalary")
    public Object personalSalary(@RequestParam("sid") Integer sid, Model model) {
        List<StaffSalary> ownSalarys= staffSalaryMapper.findSalaryBySid(sid);//查找个人的每个月的工资情况
        System.out.println(ownSalarys);
        model.addAttribute("ownSalarys", ownSalarys);
        return "personalSalary";
    }

    @RequestMapping("updateSalary")
    public Object updateStaff(@RequestParam("sid") Integer sid, @RequestParam("month") String month, Model model) {
        StaffSalary staffSalary=staffSalaryMapper.findSalaryBySidMon(sid,month);//查找该员工个工资并显示到表单中方便查看来修改工资信息
        System.out.println(staffSalary);
        model.addAttribute("sid", staffSalary.getSid());
        model.addAttribute("name", staffSalary.getName());
        model.addAttribute("month", staffSalary.getMonth());
        model.addAttribute("basicSalary", staffSalary.getBasicSalary());
        model.addAttribute("bonus", staffSalary.getBonus());
        model.addAttribute("deduct", staffSalary.getDeduct());
        model.addAttribute("actualSalary", staffSalary.getActualSalary());
        model.addAttribute("remarks", staffSalary.getRemarks());
        return "updateSalary";
    }
}
